import Vue from 'vue'
import reshandler from 'services/response-handler'
/*
 * 查看是否有核销权限
 * 参数名	类型	说明
 * clientType	string	客户端类型。[0安卓、1苹果、2web、3微信]
 * methodName	string	方法名(后台区分请求标识)
 * shopId	string	店铺ID（可以为空）
 * userId	string	用户ID（不可为空）
 * keywords	List	权限key值 [“admin:activity”:卡券核销 ]
 */
//确认核销
function makeSubmitData(res) {
    alert(JSON.stringify(res));
    if(res.resultCode = '100'){
        return{
            success:true
        }
    }
}
//查看核销权限
function makeAdminData(res) {
    console.log(res.authority['admin:activity']);
    let isAdmin
    if (res.authority['admin:activity'] === '1'){
        isAdmin = true;
    }else{
        isAdmin = false
    }
    return {
        isAdmin : isAdmin
    }
}
//查看核销详情
function makeCardData(res) {
    let state;
    let type;
    switch (res.coupon.state) {
        case '0':
            state = '未开始'
            break;
        case '1':
            state = '未领取'
            break;
        case '2':
            state = '未使用'
            break;
        case '3':
            state = '已过期'
            break;
        case '4':
            state = '已使用'
            break;
        case '5':
            state = '优惠券已被领完'
            break;
    }
    /**
 * 优惠券类型列表[红包类型
 * 0:RedPacket;优惠券类型1:Coupon;实物券2:PhysicalBond;现金券3:CashCoupon;团购券4:
 * GroupCoupon;秒杀券 5:SeckillCoupon;N元抢购 6:BuyingCoupon;抵价券 7:Voucher;包邮券
 * 8:FreeShipping;满减9:FullCut;折扣券 10:Discount;满送券11:FullGift;套餐券12:Package]
 */
    switch (res.coupon.type) {
        case '0':
            type = '红包券'
            break;
        case '1':
            type = '优惠券'
            break;
        case '2':
            type = '实物券'
            break;
        case '3':
            type = '现金券'
            break;
        case '4':
            type = '团购券'
            break;
        case '5':
            type = '秒杀券'
            break;
        case '6':
            type = 'N元抢购'
            break;
        case '7':
            type = '抵价券'
            break;
        case '8':
            type = '包邮券'
            break;
        case '9':
            type = '满减券'
            break;
        case '10':
            type = '折扣券'
            break;
        case '11':
            type = '满送券'
            break;
        case '12':
            type = '套餐券'
            break;
    }
    return {
        name: res.coupon.name,
        state : state,
        shopName: res.coupon.shop.name,
        img: res.coupon.image,
        endDate: res.coupon.endDate,
        code: res.coupon.code,
        couponCodeId: res.coupon.couponCodeId,
        type: type
    }
}

export default function (params, success, fail) {
    alert(JSON.stringify(params))
    let make;
    switch (params.methodName) {
        case 'QueryRoleHasAuthority':
            make = makeAdminData
            break;
        case 'QueryCouponByVerification':
            make = makeCardData
            break;
        case 'VerificationCoupon':
            make = makeSubmitData
            break;
    }
    this.$.get(params).then(reshandler.success(success, fail, make), reshandler.error(fail))
}
